/***********************************************************************/
/** 
    Contains functions for general use.    
    
    @author Birgit Graf, UWA, 1998, modified 2000 (Mk3/4)
    modified for RAS by Mattias Bratt
*/
/***********************************************************************/


#include "helper.h"
#include "eyebot.h"



/***********************************************************************/
/** Error message.
    Print error message and end program.

    param str string, which should be printed
*/
/***********************************************************************/

void error(char str[])
{
  LCDPrintf("ERROR: %s\n", str);
  OSWait(200);
  OSExit(0);
}



float fsign(float number)
{
  if (number < 0.0)
    return -1.0;
  else
    if (number > 0.0)
      return 1.0;
    else
      return 0.0;
}


/***********************************************************************/
/** Set Parameter over keyboard (float).

    Could be called by main().

    param text[] name of parameter
    param minp,maxp minimum and maximum value of parameter 
    param start start value for parameter
    param inc step to increment parameter
*/
/***********************************************************************/

float set_fparam(char text[], float minp, float start, float maxp, float inc)
{
  float val;
  int   done = FALSE;

  LCDClear();
  LCDPrintf("Set Parameter\n%s\n", text);

  LCDMenu("+", "-", " ","OK");
  val = start;
  do
  {
    LCDSetPos(5, 0);
    LCDPrintf("%f\n", val);
    switch(KEYGet())
    {
    case KEY1:
      if (val < maxp)
	val += inc;
      break;
    case KEY2:
      if (val > minp)
	val -= inc;
      break;
    case KEY4:
      done = TRUE;
    }
  } while (!done);

  LCDClear();
  return val;
}



/***********************************************************************/
/** Set Parameter over keyboard (int).

    Called by main().

    param text[] name of parameter
    param minp,maxp minimum and maximum value of parameter 
    param start start value for parameter
    param inc step to increment parameter
*/
/***********************************************************************/

int set_iparam(char text[], int minp, int start, int maxp, int inc)
{
  int val;
  int done = FALSE;

  LCDClear();
  LCDPrintf("Set Parameter\n%s\n", text);
  LCDMenu("+", "-", " ","OK");
  val = start;
  do
  {
    LCDSetPos(5, 0);
    LCDPrintf("%3d\n", val);
    switch(KEYGet())
    {
    case KEY1:
      if (val <maxp)
	val += inc;
      break;
    case KEY2:
      if (val > minp)
	val -= inc;
      break;
    case KEY4:
      done = TRUE;
    }
  } while (!done);

  LCDClear();
  return val;
}












































































